
/*
 *
 * Copyright (c) 2006 P.J.Leonard
 * 
 * http://www.frinika.com
 * 
 * This file is part of Frinika.
 * 
 * Frinika is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.

 * Frinika is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with Frinika; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package uk.ac.bath.domains.IP;

import uk.ac.bath.environment.MachineIF;
import uk.ac.bath.util.MyRandom;

/**
 *
 * @author pjl
 */
public class IPSetup implements IPSetupIF {

    float one_degree = 0.0174532f;	/* 2pi/360 */
    float six_degrees = 0.1047192f;
    float twelve_degrees = 0.2094384f;
    float fifty_degrees = 0.87266f;

    public int getNIn() {
        return 4;
    }

    public int getNOut() {
        return 2;
    }

    @Override
    public boolean hasFailed(CartSimIF sim) {

        IPModelIF model=sim.getModel();
        /*--- Check for failure.  If so, return steps ---*/
        if (!model.isOverriden()) {
            if (model.getX() < -2.4 || model.getX() > 2.4 || model.getPhi() < -twelve_degrees ||
                    model.getPhi() > twelve_degrees) {
                return true;
            }
        }
        return false;
    }

    @Override
    public CartSimIF newCartSim(MachineIF currentMachine) {

        float x = (float) (0.5 * (MyRandom.nextInt(4800) / 1000.0 - 2.4));
        float x_dot = (float) (0.5 * (MyRandom.nextInt(2000) / 1000.0 - 1.0));
        float theta = (float) (0.5 * (MyRandom.nextInt(400) / 1000.0 - .2));
        float theta_dot = (float) (0.5 * (MyRandom.nextInt(3000) / 1000.0 - 1.5));

        return newCartSimImpl(currentMachine, x, x_dot, theta, theta_dot);
    }

    protected CartSimIF newCartSimImpl(MachineIF net, float x, float x_dot, float theta, float theta_dot) {
        return new CartSim(net, x, x_dot, theta, theta_dot);
    }

    public String reportSetup() {
        return " IP original sane target";
    }

  
}
